package 剑指offer;

/**
 * @ClassName _58左旋转字符串
 * @Description TODO
 * @Author 昝亚杰
 * @Date 2022/2/24 20:40
 * Version 1.0
 **/
public class _58左旋转字符串 {
    public String reverseLeftWords(String s, int n) {
        int length = s.length();
        StringBuffer stringBuffer = new StringBuffer();
        String left = reverse(s.substring(0,n));
        String right = reverse(s.substring(n,s.length()));
        StringBuffer newString = stringBuffer.append(left).append(right);
        return reverse(newString.toString());
    }
    public String reverse(String s){
        char[] chars = s.toCharArray();
        int start = 0,end = s.length() - 1;
        for(int i = start,j = end; start < end; start++,end--){
            char temp = chars[start];
            chars[start] = chars[end];
            chars[end] = temp;
        }
        return String.valueOf(chars);
    }
}
